﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace text.StrProblem
{
    public class _43
    {
        public string Multiply(string num1, string num2)
        {
            if (num1.Equals("0") || num2.Equals("0"))
            {
                return "0";
            }
            int[] res = new int[num1.Length + num2.Length];
            for (int i = num1.Length - 1; i >= 0; i--)
            {
                int n1 = num1[i] - '0';
                for (int j = num2.Length - 1; j >= 0; j--)
                {
                    int n2 = num2[j] - '0';
                    int sum = (res[i + j + 1] + n1 * n2);
                    res[i + j + 1] = sum % 10;
                    res[i + j] += sum / 10;
                }
            }
            StringBuilder result = new StringBuilder();
            for (int i = 0; i < res.Length; i++)
            {
                if (i == 0 && res[i] == 0) continue;
                result.Append(res[i]);
            }
            return result.ToString();
        }
    }
}
